/*     */ package com.zimbra.qa.unittest.prov.soap;
/*     */ 
/*     */ import com.google.common.collect.Lists;
/*     */ import com.zimbra.common.soap.SoapTransport;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Group;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.GranteeType;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.User;
/*     */ import com.zimbra.cs.account.accesscontrol.TargetType;
/*     */ import com.zimbra.cs.account.accesscontrol.UserRight;
/*     */ import com.zimbra.qa.QA.Bug;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import com.zimbra.qa.unittest.prov.Verify;
/*     */ import com.zimbra.soap.account.message.DiscoverRightsRequest;
/*     */ import com.zimbra.soap.account.message.DiscoverRightsResponse;
/*     */ import com.zimbra.soap.account.type.DiscoverRightsInfo;
/*     */ import com.zimbra.soap.account.type.DiscoverRightsTarget;
/*     */ import com.zimbra.soap.admin.type.GranteeSelector.GranteeBy;
/*     */ import com.zimbra.soap.type.TargetBy;
/*     */ import java.util.Collections;
/*     */ import java.util.List;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestDiscoverRights
/*     */   extends SoapTest
/*     */ {
/*     */   private static SoapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   private static String DOMAIN_NAME;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  57 */     provUtil = new SoapProvTestUtil();
/*  58 */     prov = provUtil.getProv();
/*  59 */     domain = provUtil.createDomain(baseDomainName());
/*  60 */     DOMAIN_NAME = domain.getName();
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  65 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   private String getAddress(String localpart)
/*     */   {
/*  70 */     return TestUtil.getAddress(localpart, DOMAIN_NAME);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   @Test
/*     */   @QA.Bug(bug={68225})
/*     */   public void displayName()
/*     */     throws Exception
/*     */   {
/*  80 */     Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
/*     */     
/*  82 */     String GROUP_1_NAME = getAddress(genGroupNameLocalPart("1"));
/*  83 */     String GROUP_1_DISPLAY_NAME = "third";
/*  84 */     String GROUP_2_NAME = getAddress(genGroupNameLocalPart("2"));
/*  85 */     String GROUP_2_DISPLAY_NAME = "first";
/*  86 */     String GROUP_3_NAME = getAddress(genGroupNameLocalPart("3"));
/*  87 */     String GROUP_3_DISPLAY_NAME = "first";
/*     */     
/*  89 */     Group group1 = provUtil.createGroup(GROUP_1_NAME, Collections.singletonMap("displayName", GROUP_1_DISPLAY_NAME), false);
/*     */     
/*     */ 
/*  92 */     Group group2 = provUtil.createGroup(GROUP_2_NAME, Collections.singletonMap("displayName", GROUP_2_DISPLAY_NAME), false);
/*     */     
/*     */ 
/*  95 */     Group group3 = provUtil.createGroup(GROUP_3_NAME, Collections.singletonMap("displayName", GROUP_3_DISPLAY_NAME), false);
/*     */     
/*     */ 
/*     */ 
/*  99 */     String RIGHT_NAME = Rights.User.R_ownDistList.getName();
/*     */     
/* 101 */     prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group1.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, acct.getName(), null, RIGHT_NAME, null);
/*     */     
/*     */ 
/* 104 */     prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group2.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, acct.getName(), null, RIGHT_NAME, null);
/*     */     
/*     */ 
/* 107 */     prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group3.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, acct.getName(), null, RIGHT_NAME, null);
/*     */     
/*     */ 
/*     */ 
/* 111 */     SoapTransport transport = authUser(acct.getName());
/*     */     
/* 113 */     DiscoverRightsRequest req = new DiscoverRightsRequest(Collections.singletonList(RIGHT_NAME));
/*     */     
/* 115 */     DiscoverRightsResponse resp = (DiscoverRightsResponse)invokeJaxb(transport, req);
/*     */     
/* 117 */     List<DiscoverRightsInfo> rightsInfo = resp.getDiscoveredRights();
/* 118 */     Assert.assertEquals(1L, rightsInfo.size());
/*     */     
/* 120 */     List<String> result = Lists.newArrayList();
/*     */     
/* 122 */     for (DiscoverRightsInfo rightInfo : rightsInfo) {
/* 123 */       List<DiscoverRightsTarget> targets = rightInfo.getTargets();
/*     */       
/* 125 */       for (DiscoverRightsTarget target : targets) {
/* 126 */         String id = target.getId();
/* 127 */         String name = target.getName();
/* 128 */         String displayName = target.getDisplayName();
/*     */         
/* 130 */         result.add(Verify.makeResultStr(new Object[] { id, name, displayName }));
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*     */ 
/* 136 */     Verify.verifyEquals(Lists.newArrayList(new String[] { Verify.makeResultStr(new Object[] { group2.getId(), group2.getName(), group2.getDisplayName() }), Verify.makeResultStr(new Object[] { group3.getId(), group3.getName(), group3.getDisplayName() }), Verify.makeResultStr(new Object[] { group1.getId(), group1.getName(), group1.getDisplayName() }) }), result);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   @Test
/*     */   public void granteeAll()
/*     */     throws Exception
/*     */   {
/* 146 */     Domain testDomain = provUtil.createDomain(genDomainName(domain.getName()));
/* 147 */     Account acct = provUtil.createAccount(genAcctNameLocalPart(), testDomain);
/*     */     
/* 149 */     String RIGHT_NAME = "createDistList";
/*     */     
/* 151 */     prov.grantRight(TargetType.domain.getCode(), TargetBy.name, testDomain.getName(), GranteeType.GT_AUTHUSER.getCode(), null, null, null, RIGHT_NAME, null);
/*     */     
/*     */ 
/*     */ 
/* 155 */     SoapTransport transport = authUser(acct.getName());
/*     */     
/* 157 */     DiscoverRightsRequest req = new DiscoverRightsRequest(Collections.singletonList(RIGHT_NAME));
/*     */     
/* 159 */     DiscoverRightsResponse resp = (DiscoverRightsResponse)invokeJaxb(transport, req);
/*     */     
/* 161 */     List<DiscoverRightsInfo> rightsInfo = resp.getDiscoveredRights();
/*     */     
/* 163 */     List<String> result = Lists.newArrayList();
/* 164 */     for (DiscoverRightsInfo rightInfo : rightsInfo) {
/* 165 */       List<DiscoverRightsTarget> targets = rightInfo.getTargets();
/*     */       
/* 167 */       for (DiscoverRightsTarget target : targets) {
/* 168 */         String id = target.getId();
/* 169 */         String name = target.getName();
/*     */         
/* 171 */         result.add(Verify.makeResultStr(new Object[] { id, name }));
/*     */       }
/*     */     }
/*     */     
/* 175 */     Verify.verifyEquals(Lists.newArrayList(new String[] { Verify.makeResultStr(new Object[] { testDomain.getId(), testDomain.getName() }) }), result);
/*     */     
/*     */ 
/*     */ 
/* 179 */     provUtil.deleteAccount(acct);
/* 180 */     provUtil.deleteDomain(testDomain);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/soap/TestDiscoverRights.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */